package koscom.corebase.nam;

import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;


@SuppressWarnings("serial")
public class Login extends JFrame {
	
	private JPanel contentPane;
	private JTextField IDTextField;
	private JPasswordField PWTextField;
	JButton loginBtn;
	Image loginImage2;
	Image loginImage;
	private JTextField resultTextField;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Login frame = new Login();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}
	
	public void doLogin()
	{
		//TODO : 로그인 하자.
		System.out.println("login! 만들어야하지!");
		resultTextField.setText("login 만들자!");
	}
	
	/**
	 * Create the frame.
	 */
	public Login() {
		setUndecorated(true);
		//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(700, 350, 450, 318);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(10,20,30));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);
		
		JLabel IDLabel = new JLabel("");
		
		IDLabel.setIcon(new ImageIcon(new ImageIcon("img\\id.png").getImage().getScaledInstance(282, 40, java.awt.Image.SCALE_SMOOTH)));
		IDLabel.setBounds(35, 121, 282, 38);
		contentPane.add(IDLabel);
		
		JLabel PWLabel = new JLabel("");
		PWLabel.setIcon(new ImageIcon(new ImageIcon("img\\pe.png").getImage().getScaledInstance(282, 40, java.awt.Image.SCALE_SMOOTH)));
		PWLabel.setBounds(35, 169, 282, 38);
		contentPane.add(PWLabel);
		
		JLabel CBLabel = new JLabel("CoreBASE");
		CBLabel.setFont(new Font("Consolas", Font.BOLD, 44));
		CBLabel.setForeground(Color.WHITE);
		CBLabel.setBounds(35, 73, 192, 38);
		contentPane.add(CBLabel);
		
		JLabel loginLabel = new JLabel("login");
		loginLabel.setForeground(Color.WHITE);
		loginLabel.setFont(new Font("Consolas", Font.BOLD, 28));
		loginLabel.setBounds(239, 77, 192, 38);
		contentPane.add(loginLabel);
		
		
		ImageIcon lg = new ImageIcon("img\\lg.png");
		Image lgImage = lg.getImage();  
		loginImage = lgImage.getScaledInstance(141, 55, java.awt.Image.SCALE_SMOOTH);
		
		
		ImageIcon lg2 = new ImageIcon("img\\lg2.png");
		Image lgImage2 = lg2.getImage();  
		loginImage2 = lgImage2.getScaledInstance(141, 55, java.awt.Image.SCALE_SMOOTH);
		
		loginBtn = new JButton("");
		loginBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				doLogin();
			}
		});
		loginBtn.addMouseListener(new MouseAdapter() {
			@Override
			public void mousePressed(MouseEvent e) {
				loginBtn.setIcon(new ImageIcon(loginImage2));
			}
			@Override
			public void mouseReleased(MouseEvent e) {
				loginBtn.setIcon(new ImageIcon(loginImage));
			}
		});
		loginBtn.setSelected(true);
		loginBtn.setBorder(BorderFactory.createEmptyBorder());
		loginBtn.setContentAreaFilled(false);
		loginBtn.setBorderPainted(false);
		loginBtn.setBorder(null);
		loginBtn.setBounds(35, 224, 141, 55);
		loginBtn.setIcon(new ImageIcon(loginImage));
		contentPane.add(loginBtn);
		
		IDTextField = new JTextField();
		IDTextField.setFont(new Font("Consolas", Font.PLAIN, 14));
		IDTextField.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				IDTextField.setText("");
				PWTextField.setText("");
			}
		});
		IDTextField.addKeyListener(new KeyAdapter() {
			@Override
			public void keyPressed(KeyEvent e) {
				if (e.getKeyCode() == KeyEvent.VK_ENTER) {
		            IDTextField.setFocusable(false);
		            PWTextField.setFocusable(true);
				}
			}
		});
		
		IDTextField.setBackground(new Color(242, 242, 242));
		IDTextField.setBorder(new EmptyBorder(0, 0, 0, 0));
		IDTextField.setBounds(122, 131, 185, 21);
		contentPane.add(IDTextField);
		IDTextField.setColumns(10);
		
		PWTextField = new JPasswordField();
		PWTextField.setFont(new Font("Consolas", Font.PLAIN, 14));
		PWTextField.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				PWTextField.setText("");
			}
		});
		PWTextField.addFocusListener(new FocusAdapter() {
			@Override
			public void focusGained(FocusEvent e) {
				IDTextField.setFocusable(true);
			}
		});
		PWTextField.addKeyListener(new KeyAdapter() {
			@Override
			public void keyTyped(KeyEvent e) {
				if(e.getKeyChar() == KeyEvent.VK_ENTER)
				{
					doLogin();
				}
				//
			}
			@Override
			public void keyPressed(KeyEvent e) {
				if(e.getKeyChar() == KeyEvent.VK_ENTER)
				{
					loginBtn.setIcon(new ImageIcon(loginImage2));
				}
			}
			@Override
			public void keyReleased(KeyEvent e) {
				if(e.getKeyChar() == KeyEvent.VK_ENTER)
				{
					loginBtn.setIcon(new ImageIcon(loginImage));
				}
			}
		});
		
		PWTextField.setBackground(new Color(242, 242, 242));
		PWTextField.setBorder(new EmptyBorder(0, 0, 0, 0));
		PWTextField.setColumns(10);
		PWTextField.setBounds(122, 179, 185, 21);
		contentPane.add(PWTextField);
		
		JButton closeBtn = new JButton("close");
		closeBtn.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				System.exit(0);
			}
		});
		closeBtn.setRolloverEnabled(false);
		closeBtn.setBorderPainted(false);
		closeBtn.setFocusPainted(false);
		closeBtn.setBorder(new EmptyBorder(0, 0, 0, 0));
		closeBtn.setBounds(239, 256, 68, 23);
		closeBtn.setBackground(new Color(10,20,30));
		closeBtn.setForeground(new Color(242, 242, 242));
		contentPane.add(closeBtn);
		
		resultTextField = new JTextField();
		resultTextField.setText("서버 다운...");
		resultTextField.setEditable(false);
		resultTextField.setFont(new Font("맑은 고딕", Font.BOLD, 12));
		resultTextField.setBorder(new EmptyBorder(0, 0, 0, 0));
		resultTextField.setForeground(Color.ORANGE);
		resultTextField.setBounds(35, 287, 354, 21);
		contentPane.add(resultTextField);
		resultTextField.setColumns(10);
		resultTextField.setBackground(new Color(10,20,30));
		
	}
}
